package com.zyy.smartcity1129.work;

import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.zyy.smartcity1129.BaseFragment;
import com.zyy.smartcity1129.R;
import com.zyy.smartcity1129.data.DeliRecordInfo;
import com.zyy.smartcity1129.data.UserInfo;
import com.zyy.smartcity1129.util.Http;
import com.zyy.smartcity1129.util.RvAd;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName: DeliveryRecordFragment$
 * @Description: 作用
 * @Author: letquit
 * @CreateDate: 6/12/2021$
 * @Version: 1.0
 */
public class DeliveryRecordFragment extends BaseFragment {
    private RecyclerView rvOnly;
    private Button btnNext;

    @Override
    protected int layId() {
        return R.layout.f_rv_only;
    }

    @Override
    protected String title() {
        return null;
    }

    @Override
    protected boolean back() {
        return false;
    }

    @Override
    protected Boolean bottom() {
        return false;
    }

    @Override
    protected void init(View iv) {
        WorkFragment.mutableLiveData.postValue("投递记录");
        initView(iv);
        rvOnly.setLayoutManager(new LinearLayoutManager(getContext()));
        th(() -> {
            UserInfo.UserBean userBean = Http.getInstance().get("/prod-api/api/common/user/getInfo", null, UserInfo.class, 1).getUser();
            List<DeliRecordInfo.RowsBean> recordList = Http.getInstance().get("/prod-api/api/job/deliver/list?userId=" + userBean.getUserId(), null, DeliRecordInfo.class, 1).getRows();
            List<DeliRecordInfo.RowsBean> mRecordList = recordList.stream().filter(a -> (!a.getPostName().equals(""))).collect(Collectors.toList());
            RvAd<DeliRecordInfo.RowsBean> rvAd = new RvAd<DeliRecordInfo.RowsBean>(mRecordList, R.layout.rv_base) {
                private void initView(View vi) {
                    ig = (ImageView) vi.findViewById(R.id.ig);
                    view = (View) vi.findViewById(R.id.view);
                    lineRvPatient = (LinearLayout) vi.findViewById(R.id.lineRvPatient);
                    tv1 = (TextView) vi.findViewById(R.id.tv1);
                    tv2 = (TextView) vi.findViewById(R.id.tv2);
                    tv3 = (TextView) vi.findViewById(R.id.tv3);
                    tv4 = (TextView) vi.findViewById(R.id.tv4);
                    tv5 = (TextView) vi.findViewById(R.id.tv5);
                    tv6 = (TextView) vi.findViewById(R.id.tv6);
                    tv7 = (TextView) vi.findViewById(R.id.tv7);
                    imgRvPatient = (ImageView) vi.findViewById(R.id.imgRvPatient);
                    imgDowm = (ImageView) vi.findViewById(R.id.imgDowm);
                    rv = (RecyclerView) vi.findViewById(R.id.rv);
                    ig.setVisibility(View.GONE);
                    view.setVisibility(View.GONE);
                    tv5.setVisibility(View.GONE);
                }

                private RecyclerView rv;
                private ImageView imgDowm;
                private ImageView imgRvPatient;
                private TextView tv7;
                private TextView tv6;
                private TextView tv5;
                private TextView tv4;
                private TextView tv3;
                private TextView tv2;
                private TextView tv1;
                private LinearLayout lineRvPatient;
                private View view;
                private ImageView ig;

                @Override
                protected void initR(View vi, DeliRecordInfo.RowsBean rowsBean, int p) {
                    initView(vi);
                    tv1.setText("岗位名称：" + rowsBean.getPostName());
                    tv2.setText("公司名称：" + rowsBean.getCompanyName());
                    tv3.setText("     薪资:" + rowsBean.getMoney() + "元");
                    tv4.setText("投递简历时间：" + rowsBean.getSatrTime());
                }
            };
            ui(() -> {
                rvOnly.setAdapter(rvAd);
            });
        });
    }

    private void initView(View iv) {
        rvOnly = (RecyclerView) iv.findViewById(R.id.rvOnly);
        btnNext = (Button) iv.findViewById(R.id.btnNext);
    }
}
